using UnityEngine;
using System.Collections;

/// \class  gkSpawningAltitudeInGame
/// \brief  Select altitude
[AddComponentMenu("GK/Engine/Game/Spawn/gkSpawningAltitudeInGame")]
public class gkSpawningAltitudeInGame : gkSpawningModifier
{
    /// The drop altitude in screen percent
    public float DropAltitudePercent;

    /// The game volume bounding box
    Bounds m_oGameVolumeBoudingBox;

    /// \brief  Called just after the game begin to play
    void Start()
    {
	   // Get the spawning volume bounding box
	   gkUtilityBounds.GrabColliderOrRendererBounds(GameObject.Find("GameVolume"), out m_oGameVolumeBoudingBox);
    }

    /// \brief  Event called at the and of the actor spawn
    public override void ModifySpawnedActor(GameObject a_rSpawnedActor, int a_iNumActorsInCurrentBatch, int a_iNbActorsInCurrentBatch)
    {
	    SetAltitude(a_rSpawnedActor);
    }

    /// \brief  Set a fixed altitude that is in the game volume
    void SetAltitude(GameObject a_rSpawnedActor)
    {
	    Vector3 f3SpawnedPosition;
	    float fVolumeHeight;

	    // Get the current position
	    f3SpawnedPosition = a_rSpawnedActor.transform.position;
    	
	    // Compute the altitude
	    fVolumeHeight = m_oGameVolumeBoudingBox.max.y - m_oGameVolumeBoudingBox.min.y;
	    f3SpawnedPosition.y = m_oGameVolumeBoudingBox.min.y + fVolumeHeight * DropAltitudePercent;

	    // Set the new position
	    a_rSpawnedActor.transform.position = f3SpawnedPosition;
    }
}
